package com.demo.designpattern.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hunter
 *
 * @Description 老师-被观察者
 */
public class Teacher implements Subject {

    private final List<Observer> watchers = new ArrayList<>();

    @Override
    public void addObserver(Observer observer) {
        watchers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        watchers.remove(observer);
    }

    @Override
    public void doNotifyAll() {
        for (Observer watch : watchers) {
            watch.doNotify();
        }
    }

    @Override
    public void doSomeThings() {
        System.out.println("老师发布作业啦...");
        doNotifyAll();
    }
}
